package 笔试.bilibili笔试.第一题24点;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
//4个1-10的数字，加减乘除运算，得到24就得到胜利
public class Solution
{
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = "";
        while ((line = br.readLine()) != null) {
            String[] strs = line.split(" ");
            List<Integer> list = new ArrayList<Integer>();
            for (int i = 0; i < 4; i++) {
                list.add(Integer.parseInt(strs[i]));
            }
            boolean flag = method(list);
            System.out.println(flag);
        }
    }
    public boolean Game24Points (int[] arr)
    {
        ArrayList<Integer> list = new ArrayList<>();

        for (int i = 0; i < arr.length; i++)
        {
            list.add(arr[i]);
        }
        return method(list);

    }

    public static boolean method(List<Integer> list)
    {
        for (int i = 0; i < list.size(); i++)
        {
            int temp = list.get(i);
            list.remove(i);
            if (helper(list, temp))
                return true;
            list.add(i, temp);
        }
        return false;
    }

    public static boolean helper(List<Integer> list, int temp)
    {
        if (list.size() > 0)
        {
            for (int i = 0; i < list.size(); i++)
            {
                int n = list.get(i);
                list.remove(i);
                if (helper(list, temp * n) || helper(list, temp + n) || helper(list, temp - n))
                    return true;
                else if (temp % n == 0)
                {
                    if (helper(list, temp / n))
                        return true;
                }
                list.add(i, n);
            }
            return false;
        }
        else
        {
            if (temp == 24)
                return true;
            else
                return false;
        }
    }

}
